package com.example.administrator.officeplatform.Audit;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.bean.CostInfo;
import com.example.administrator.officeplatform.bean.TravelExpensesFormDetailVoInfo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/23.
 */

public class TravelExpensesFormDetailAdapter extends RecyclerView.Adapter{
//    public static interface OnRecyclerViewListener {
//        void onItemClick(int position);
//
//        boolean onItemLongClick(int position);
//    }

//    private OnRecyclerViewListener onRecyclerViewListener;
//
//    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
//        this.onRecyclerViewListener = onRecyclerViewListener;
//    }

    private List<TravelExpensesFormDetailVoInfo> list = new ArrayList<>();
    private Context mContext;

    public TravelExpensesFormDetailAdapter(List<TravelExpensesFormDetailVoInfo> list, Context mContext) {
        this.list = list;
        this.mContext=mContext;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_travelexpensesformdetail, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PersonViewHolder personViewHolder = (PersonViewHolder) holder;
        personViewHolder.position = position;
        TravelExpensesFormDetailVoInfo travelExpensesFormDetailVoInfo= list.get(position);
        DecimalFormat format = new DecimalFormat("0.00");


        personViewHolder.tv_starttime.setText("时间:"+travelExpensesFormDetailVoInfo.getSetoutTime());
        personViewHolder.tv_startaddress.setText("地点:"+travelExpensesFormDetailVoInfo.getSetoutAddress());
        personViewHolder.tv_arrivetime.setText("时间:"+travelExpensesFormDetailVoInfo.getArriveTime());
        personViewHolder.tv_arriveaddress.setText("地点:"+travelExpensesFormDetailVoInfo.getArriveAddress());
        personViewHolder.tv_citylevel.setText("城市等级:"+travelExpensesFormDetailVoInfo.getArriveCityLeave());
        personViewHolder.tv_trafficnum.setText("单据张数:"+travelExpensesFormDetailVoInfo.getTrafficBillNumber());
        personViewHolder.tv_trafficmoney.setText("金额:"+"￥"+format.format(travelExpensesFormDetailVoInfo.getTrafficMoney()));
        personViewHolder.tv_days.setText("天数:"+travelExpensesFormDetailVoInfo.getTravelDay());
        personViewHolder.tv_daymoney.setText("金额:"+"￥"+format.format(travelExpensesFormDetailVoInfo.getTravelMoney()));
        if(travelExpensesFormDetailVoInfo.getOtherProject()==null){
            personViewHolder.tv_xm.setText("项目:");
        }else{
            personViewHolder.tv_xm.setText("项目:"+travelExpensesFormDetailVoInfo.getOtherProject());
        }
        personViewHolder.tv_djnumber.setText("单据张数:"+travelExpensesFormDetailVoInfo.getOtherBillNumber());
        personViewHolder.tv_xmmoney.setText("金额:"+"￥"+format.format(travelExpensesFormDetailVoInfo.getOtherMoney()));

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class PersonViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public int position;
        public TextView tv_starttime,tv_startaddress,tv_arrivetime,tv_arriveaddress,
                tv_citylevel,tv_trafficnum,tv_trafficmoney,tv_days,tv_daymoney
                ,tv_xm,tv_djnumber,tv_xmmoney;

        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_starttime = (TextView)itemView.findViewById(R.id.tv_starttime);
            tv_startaddress = (TextView)itemView.findViewById(R.id.tv_startaddress);
            tv_arrivetime = (TextView)itemView.findViewById(R.id.tv_arrivetime);
            tv_arriveaddress = (TextView)itemView.findViewById(R.id.tv_arriveaddress);
            tv_citylevel = (TextView)itemView.findViewById(R.id.tv_citylevel);
            tv_trafficnum = (TextView)itemView.findViewById(R.id.tv_trafficnum);
            tv_trafficmoney = (TextView)itemView.findViewById(R.id.tv_trafficmoney);
            tv_days = (TextView)itemView.findViewById(R.id.tv_days);
            tv_daymoney = (TextView)itemView.findViewById(R.id.tv_daymoney);
            tv_xm = (TextView)itemView.findViewById(R.id.tv_xm);
            tv_djnumber = (TextView)itemView.findViewById(R.id.tv_djnumber);
            tv_xmmoney = (TextView)itemView.findViewById(R.id.tv_xmmoney);



            rootView = itemView.findViewById(R.id.ll);
//            rootView.setOnClickListener(this);
//            rootView.setOnLongClickListener(this);
        }

//        @Override
//        public void onClick(View v) {
//            if (null != onRecyclerViewListener) {
//                onRecyclerViewListener.onItemClick(position);
//            }
//        }
//
//        @Override
//        public boolean onLongClick(View v) {
//            if (null != onRecyclerViewListener) {
//                return onRecyclerViewListener.onItemLongClick(position);
//            }
//            return false;
//        }
    }
}
